package com.oig.common.util;


import com.oig.common.constants.BasicConstants;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.Date;

public class IdNumberUtil {

    private IdNumberUtil(){}


    public static String getNextNumber(Integer index, String pre){
        return getNextNumber(index, BasicConstants.ORDER_LEN, pre, BasicConstants.DEF_PAD);
    }


    public static String getNextNumber(Integer index, Integer len, String pre, String padStr){
        String idStr = StringUtils.leftPad(String.valueOf(index), len, padStr);
        String dayStr = DateFormatUtils.format(new Date(), BasicConstants.DAY_STR_FORMAT);
        return  pre + dayStr + idStr ;
    }

    /**
     * 在id前面补0
     * @param id
     * @param totalDigits 总共多少位
     * @return
     */
    public static String addZeroBefore(Integer id, int totalDigits){
        String format = "%0" + totalDigits + "d";
        return String.format(format, id);
    }


}
